﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VMuktiAPI;

namespace VMuktiGrid.CustomMenu
{
    /// <summary>
    /// Interaction logic for addBuddy.xaml
    /// </summary>
    public partial class ctlExpMenuItem : UserControl
    {

        public string strLeftImage
        {
            set
            {
                if (value == "")
                {
                    //imgLeftIcon.Source = null;
                }
                else
                {
                    //imgLeftIcon.Source = new BitmapImage(new Uri(value, UriKind.RelativeOrAbsolute));
                }
            }
        }

        public string strRightImage
        {
            set
            {
                if (value == "")
                {
                    //imgRightIcon.Source = null;
                }
                else
                {
                    //imgRightIcon.Source = new BitmapImage(new Uri(value, UriKind.RelativeOrAbsolute));
                }
            }
        }

        public ctlExpMenuItem()
        {
            try
            {
                InitializeComponent();

                txtTitle.MouseDown += new System.Windows.Input.MouseButtonEventHandler(txtTitle_MouseDown);
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "ctlExpMenuItem()--:--ctlExpMenuItem.xaml.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
            }
        }
       
        #region Public Properties

        public string Title
        {
            set
            {
                txtTitle.Text = value;
            }
        }

        #endregion

        #region Private Members

        private void txtTitle_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {

        }

        #endregion

        private void btnPopUP_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ItemSelected(sender);
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "btnPopUP_Click()--:--ctlExpMenuItem.xaml.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
            }
        }

        private void txtTitle_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                ItemSelected(sender);
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "txtTitle_PreviewMouseLeftButtonDown()--:--ctlExpMenuItem.xaml.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
            }
        }

        private void ItemSelected(object sender)
        {
            try
            {
                //rowSecond.Height = new GridLength(200);
                if (objBuddyList.Visibility == Visibility.Visible)
                {
                    ((RotateTransform)((TransformGroup)btnPopUP.GetValue(Button.RenderTransformProperty)).Children[2]).Angle = -90;
                    objBuddyList.Visibility = Visibility.Collapsed;
                }
                else
                {
                    ((RotateTransform)((TransformGroup)btnPopUP.GetValue(Button.RenderTransformProperty)).Children[2]).Angle = 0;
                    objBuddyList.Visibility = Visibility.Visible;
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "ItemSelected()--:--ctlExpMenuItem.xaml.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
            }
        }

        public bool AddBuddy(string strBuddyName)
        {
            try
            {
                return objBuddyList.AddBuddy(strBuddyName);
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "AddBuddy()--:--ctlExpMenuItem.xaml.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
                return false;
            }
        }
    }
}
